import fetch from '@/utils/fetch'

//产品
export function getProductList(params, option = {
  showLoading: true
}) {
  return fetch(Object.assign({
    url: '/products',
    method: 'get',
    params: params
  }, option))
}

//添加产品
export function addProduct(data, option = {
  showLoading: true
}) {
  return fetch(Object.assign({
    url: '/products',
    method: 'post',
    data: data
  }, option))
}

//修改产品
export function updateProduct(id, data, option = {
  showLoading: true
}) {
  return fetch(Object.assign({
    url: '/products/' + id,
    method: 'put',
    data: data
  }, option))
}

//删除产品
export function deleteProduct(id, data, option = {
  showLoading: true
}) {
  return fetch(Object.assign({
    url: '/products/' + id,
    method: 'delete',
  }, option))
}

//添加设备
export function addDeviceByProduct(ProductKey, DeviceName) {
  return fetch({
    url: '/devices',
    method: 'post',
    data: {
      ProductKey: ProductKey,
      DeviceName: DeviceName
    }
  })
}
//根据产品获取设备列表
export function getDeviceByProduct(params, option = {
  showLoading: true
}) {
  return fetch({
    url: '/devices',
    method: 'get',
    params: params
  })
}

//删除设备
export function deleteDevice(id, data, option = {
  showLoading: true
}) {
  return fetch(Object.assign({
    url: '/devices/' + id,
    method: 'delete',
  }, option))
}

//查询设备信息

export function getDeviceDetail(id, option = {
  showLoading: true
}) {
  return fetch({
    url: '/devices/'+id,
    method: 'get',
  })
}

//向topic发消息

export function sendToTopic(id,data,option = {
  showLoading: true
}) {
  return fetch({
    url: "/devices/"+id+"/sendToTopic",
    method: 'post',
    data:data
  })
}

//向设备发消息

export function sendToDevice(id,data, option = {
  showLoading: true
}) {
  return fetch({
    url: "/devices/"+id+"/sendToDevice",
    method: 'post',
    data:data
  })
}